﻿<c:BaseControl x:Class="personalplaner.gui.plugins.dienstplan.views.PrintView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:bs="clr-namespace:personalplaner.business.stamm;assembly=personalplaner.business"
             xmlns:bp="clr-namespace:personalplaner.business.dienstplan.plancollection;assembly=personalplaner.business"
             xmlns:conv="clr-namespace:personalplaner.common.converters;assembly=personalplaner.common"
        xmlns:vm="clr-namespace:personalplaner.common.mvvm.factory;assembly=personalplaner.common"
        xmlns:fac="clr-namespace:personalplaner.gui.plugins.dienstplan.viewmodels.factories"
        vm:ViewModelLoader.FactoryType="{x:Type fac:PrintViewModelFactory}"
        xmlns:c="clr-namespace:personalplaner.common.controls;assembly=personalplaner.common"
               xmlns:p="clr-namespace:personalplaner.gui.Properties" Name="baseControl"
        Foreground="#E1000000">

    <Control.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/personalplaner.common;component/resources/styles/WhiteStyleTemplates.xaml"/>
                <ResourceDictionary>
                    <conv:PrinterLocationConverter x:Key="printLocationConv"/>
                    <conv:PrinterNameToImageConverter x:Key="printerImageConv"/>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Control.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="250"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>

        <GroupBox Margin="5,5,5,0" Padding="5" BorderThickness="0">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>
                
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Button Width="60" Command="{Binding PrintCommand}">
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Image Source="/personalplaner.gui;component/resources/images/Printer_32.png" Width="32" />
                            <TextBlock Text="Drucken" Grid.Row="1"/>
                        </Grid>
                    </Button>

                    <GroupBox Header="Drucken" Grid.Column="1" Margin="5,0,5,0" Padding="0,5,0,0" BorderThickness="0">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>

                            <TextBlock Text="Exemplare:" Margin="0,0,5,0" Grid.Column="0"/>

                            <c:NumericTextBox Grid.Column="1" Text="{Binding Copies}"/>
                            
                        </Grid>
                    </GroupBox>
                </Grid>
                
                <GroupBox Grid.Row="1" Header="Plan Einstellungen" Padding="0,0,0,0" BorderThickness="0" Margin="0,10,0,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        
                        <TextBlock Text="Teams"  FontWeight="Heavy" Margin="0,5,0,0" />
                        <ComboBox ItemsSource="{Binding Teams}" SelectedItem="{Binding SelectedTeam}" DisplayMemberPath="Name" Grid.Row="1"/>

                        <TextBlock Grid.Row="2" Text="{x:Static p:Resources.NamensDarstellung}" FontWeight="Heavy" Margin="0,5,0,0"/>
                        <ComboBox Grid.Row="3" ItemsSource="{Binding NameDisplayOptions}" SelectedItem="{Binding SelectedNameDisplayOption}" />
                            
                        <CheckBox Grid.Row="4" IsChecked="{Binding PrintSaldoDifference}">
                            <TextBlock Text="Diferenz / Saldo andrucken"  FontWeight="Heavy" Margin="0,5,0,0" />
                        </CheckBox>

                        <CheckBox Grid.Row="5" IsChecked="{Binding PrintSoll}">
                            <TextBlock Text="Soll andrucken"  FontWeight="Heavy" Margin="0,5,0,0" />
                        </CheckBox>

                        <CheckBox Grid.Row="6" IsChecked="{Binding PrintHaben}">
                            <TextBlock Text="Haben andrucken"  FontWeight="Heavy" Margin="0,5,0,0" />
                        </CheckBox>

                        <CheckBox Grid.Row="7" IsChecked="{Binding ShowPensumInPlan}">
                            <TextBlock Text="Pensum andrucken" FontWeight="Heavy" Margin="0,5,0,0" />
                        </CheckBox>

                    </Grid>
                </GroupBox>

                <GroupBox Grid.Row="2" Header="Drucker" Padding="0,0,0,0" BorderThickness="0" Margin="0,10,0,0">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <ComboBox ItemsSource="{Binding Printers}"  SelectedItem="{Binding SelectedPrinter}"><!--DisplayMemberPath="Name"-->
                            <ComboBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid>
                                        <Grid.RowDefinitions>
                                            <RowDefinition/>
                                            <RowDefinition/>
                                        </Grid.RowDefinitions>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="40"/>
                                            <ColumnDefinition/>
                                        </Grid.ColumnDefinitions>

                                        <Image Grid.RowSpan="2" Source="{Binding FullName, Converter={StaticResource printerImageConv}}" Width="32"/>
                                        
                                        <TextBlock Text="{Binding Name}" Grid.Column="1" FontWeight="SemiBold" Margin="0"/>
                                        <!--<TextBlock Text="{Binding Location, Converter={StaticResource printLocationConv}}" Foreground="#AA000000" Grid.Row="1" Grid.Column="1" Margin="0,0,0,3"/>-->
                                        <TextBlock Text="{Binding FullName}" Foreground="#AA000000" Grid.Row="1" Grid.Column="1" Margin="0,0,0,3"/>
                                        
                                    </Grid>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>
                        </ComboBox>
                        
                    </Grid>
                </GroupBox>

            </Grid>
        </GroupBox>

        <GroupBox Margin="5,5,5,0" Padding="5" Grid.Column="1">
            <Grid>
                <!--<Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>-->
                <!--<Viewbox>
                    <Border BorderBrush="Black" BorderThickness="1" Width="{Binding PaperWidth}" Height="{Binding PaperHeight}" Margin="5" Background="White" >
                        <Border.BitmapEffect>
                            <DropShadowBitmapEffect Color="Black" Softness="3" Opacity=".5"/>
                        </Border.BitmapEffect>

                        <Grid Margin="20" x:Name="PrintableArea">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition />
                            </Grid.RowDefinitions>
                            <TextBlock Text="{Binding Plan.Name}" FontWeight="SemiBold" FontSize="14" Margin="0,0,0,5" />
                            <c:PlanGrid ScrollViewer.VerticalScrollBarVisibility="Disabled" Collection="{Binding Plan}" ShowPensumColumn="{Binding ShowPensumInPlan}" ShowSollColumn="{Binding PrintSoll}" ShowHabenColumn="{Binding PrintHaben}" ShowDiffColumn="{Binding PrintSaldoDifference}" ShowAnpassungColumn="False" ShowVortragColumn="False" Grid.Row="1"/>
                        </Grid>
                    </Border>
                </Viewbox>-->
                <!--<Viewbox>
                <Border BorderBrush="Black" BorderThickness="1" Width="{Binding PaperWidth}" Height="{Binding PaperHeight}" Margin="5" Background="White" >
                        <Border.BitmapEffect>
                            <DropShadowBitmapEffect Color="Black" Softness="3" Opacity=".5"/>
                        </Border.BitmapEffect>
                        <FlowDocumentPageViewer>
                            <FlowDocument IsOptimalParagraphEnabled="true" IsHyphenationEnabled="true" IsColumnWidthFlexible="false" ColumnWidth="Auto" PagePadding="Auto">
                                <Paragraph>
                                    <Grid Margin="20" x:Name="PrintableArea">
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                            <RowDefinition />
                                        </Grid.RowDefinitions>
                                        <TextBlock Text="{Binding Plan.Name}" FontWeight="SemiBold" FontSize="14" Margin="0,0,0,5" />
                                        <c:PlanGrid ScrollViewer.VerticalScrollBarVisibility="Disabled" Collection="{Binding Plan}" ShowPensumColumn="{Binding ShowPensumInPlan}" ShowSollColumn="{Binding PrintSoll}" ShowHabenColumn="{Binding PrintHaben}" ShowDiffColumn="{Binding PrintSaldoDifference}" ShowAnpassungColumn="False" ShowVortragColumn="False" Grid.Row="1"/>
                                    </Grid>
                                </Paragraph>
                            </FlowDocument>
                        </FlowDocumentPageViewer>
                    </Border>
                </Viewbox>-->

                
                <Grid.Resources>
                    <DataTemplate DataType="{x:Type bp:DienstPlanCollection}">
                        <Grid x:Name="PrintableArea" Width="{Binding DataContext.PaperWidth, ElementName=baseControl}" Height="{Binding DataContext.PaperHeight, ElementName=baseControl}" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                            <Grid Margin="48,40,48,40" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <TextBlock Text="{Binding DataContext.Plan.Name, ElementName=baseControl}" FontWeight="SemiBold" FontSize="14" Margin="0,0,0,5" />

                                <c:PlanGrid Grid.Row="1" Collection="{Binding .}" 
                                        ShowPensumColumn="{Binding DataContext.ShowPensumInPlan, ElementName=baseControl}" 
                                        ShowSollColumn="{Binding DataContext.PrintSoll, ElementName=baseControl}" 
                                        ShowHabenColumn="{Binding DataContext.PrintHaben, ElementName=baseControl}" 
                                        ShowDiffColumn="{Binding DataContext.PrintSaldoDifference, ElementName=baseControl}" 
                                        RowHeight="{Binding DataContext.RowHeight, ElementName=baseControl}"
                                        ShowAnpassungColumn="False" ShowVortragColumn="False" IsReadOnly="True" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                                            IsGridForPrinting="True"/>

                            </Grid>
                        </Grid>
                    </DataTemplate>
                    
                    <!--<c:PlanGrid ScrollViewer.VerticalScrollBarVisibility="Disabled" Collection="{Binding .}" 
                                        ShowPensumColumn="True" 
                                        ShowSollColumn="False" 
                                        ShowHabenColumn="False" 
                                        ShowDiffColumn="True" 
                                        ShowAnpassungColumn="False" ShowVortragColumn="False"/>-->

                    <!--<Style TargetType="{x:Type c:PrintPreviewItem}" x:Key="printPreviewItem">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="{x:Type c:PrintPreviewItem}">

                                    <Border BorderBrush="Transparent" BorderThickness="1" Background="Transparent" Padding="10" Margin="10" x:Name="border">
                                        <Grid Margin="40" x:Name="PrintableArea" Width="{Binding DataContext.PaperWidth, ElementName=baseControl}" Height="{Binding DataContext.PaperHeight, ElementName=baseControl}">
                                            <Grid.RowDefinitions>
                                                <RowDefinition Height="Auto"/>
                                                <RowDefinition />
                                            </Grid.RowDefinitions>

                                            <TextBlock Text="{Binding DataContext.Plan.Name, ElementName=baseControl}" FontWeight="SemiBold" FontSize="14" Margin="0,0,0,5" />

                                            <c:PlanGrid ScrollViewer.VerticalScrollBarVisibility="Disabled" Grid.Row="1" Collection="{Binding .}" 
                                        ShowPensumColumn="{Binding DataContext.ShowPensumInPlan, ElementName=baseControl}" 
                                        ShowSollColumn="{Binding DataContext.PrintSoll, ElementName=baseControl}" 
                                        ShowHabenColumn="{Binding DataContext.PrintHaben, ElementName=baseControl}" 
                                        ShowDiffColumn="{Binding DataContext.PrintSaldoDifference, ElementName=baseControl}" 
                                        RowHeight="{Binding DataContext.RowHeight, ElementName=baseControl}"
                                        ShowAnpassungColumn="False" ShowVortragColumn="False"/>

                                        </Grid>
                                    </Border>

                                    <ControlTemplate.Triggers>
                                        <Trigger Property="IsSelected" Value="True">
                                            <Setter TargetName="border" Property="BorderBrush" Value="Goldenrod"/>
                                            <Setter TargetName="border" Property="Background" Value="#60DAA520"/>
                                        </Trigger>
                                    </ControlTemplate.Triggers>
                                    
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>-->
                    
                </Grid.Resources>
                
                <c:PrintPreviewItemsControl ItemsSource="{Binding Pages}" x:Name="PrintPreview" ScrollViewer.VerticalScrollBarVisibility="Disabled" ScrollViewer.HorizontalScrollBarVisibility="Disabled"  ><!--ItemContainerStyle="{StaticResource printPreviewItem}"-->
                    <!--<c:PrintPreviewItemsControl.ItemTemplate>
                        <DataTemplate>
                            <Grid Margin="40" x:Name="PrintableArea" Width="{Binding DataContext.PaperWidth, ElementName=baseControl}" Height="{Binding DataContext.PaperHeight, ElementName=baseControl}">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition />
                                </Grid.RowDefinitions>

                                <TextBlock Text="{Binding DataContext.Plan.Name, ElementName=baseControl}" FontWeight="SemiBold" FontSize="14" Margin="0,0,0,5" />

                                <c:PlanGrid ScrollViewer.VerticalScrollBarVisibility="Disabled" Grid.Row="1" Collection="{Binding .}" 
                                        ShowPensumColumn="{Binding DataContext.ShowPensumInPlan, ElementName=baseControl}" 
                                        ShowSollColumn="{Binding DataContext.PrintSoll, ElementName=baseControl}" 
                                        ShowHabenColumn="{Binding DataContext.PrintHaben, ElementName=baseControl}" 
                                        ShowDiffColumn="{Binding DataContext.PrintSaldoDifference, ElementName=baseControl}" 
                                        RowHeight="{Binding DataContext.RowHeight, ElementName=baseControl}"
                                        ShowAnpassungColumn="False" ShowVortragColumn="False"/>

                            </Grid>
                        </DataTemplate>
                    </c:PrintPreviewItemsControl.ItemTemplate>-->
                </c:PrintPreviewItemsControl>

                <!--<TabControl ItemsSource="{Binding Pages}" Grid.Row="1" x:Name="TestTab">
                    <TabControl.ItemContainerStyle>
                        <Style TargetType="{x:Type TabItem}">
                            <Setter Property="Header" Value="test" />
                            <Setter Property="Content" Value="{Binding .}" />
                        </Style>
                    </TabControl.ItemContainerStyle>
                </TabControl>-->

            </Grid>
        </GroupBox>

        <StackPanel Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,20,40,20">
            <Button MinWidth="60" Margin="5" IsDefault="True" 
                    Command="{Binding OkCommand}">
                <TextBlock Text="OK"/>
            </Button>
            <Button MinWidth="60" Margin="5" IsCancel="True" 
                    Command="{Binding CancelCommand}">
                <TextBlock Text="Abbrechen"/>
            </Button>
        </StackPanel>
    </Grid>
    
</c:BaseControl>
